package testshop.page;

import com.sun.org.apache.bcel.internal.generic.SWITCH;
import testshop.dao.SalesManDao;
import testshop.entity.SalesMan;
import testshop.tools.ScannerChoice;

import java.util.ArrayList;

public class MainPage extends ScannerChoice {

    /*
     *入口函数
     */
    public static void main(String[] args){

         MainPage.mainPage();

    }

    //首页
    public  static void mainPage(){

        System.out.println("***************************\n");
        System.out.println("\t 1.商品维护\n");
        System.out.println("\t 2.前台收银\n");
        System.out.println("\t 3.商品管理\n");
        System.out.println("***************************");
        System.out.println("\n请输入选项,或者按0退出.");

       do {

           String input = MainPage.ScannerInfoString();
           String rex = "[0-3]";
           if (input.matches(rex)){


               int info = Integer.parseInt(input);


               switch (info){
                   case 0:

                       System.out.println("_________________");
                       System.out.println("您已经退出系统!");
                       System.exit(1);

                       break;
                   case 1 :
                       MainPage.goProductMaintenancePage();
                    break;
                   case 2 :
                       MainPage.goCashDeskPage();
                       break;
                   case 3 :
                       MainPage.goCommodityManagementPage();
                       break;
                   default:
                       System.err.println("!输入有误!");
                       System.out.println("重新选择或者按0退出.");
                       break;
               }



           }else{
               System.err.println("!输入有误!");
               System.out.println("重新选择或者按0退出.");
           }


       }while (true);




    }


    /*商品维护*/
    public static  void  goProductMaintenancePage(){

        System.out.println("***************************\n");
        System.out.println("\t 1.添加商品\n");
        System.out.println("\t 2.更改商品\n");
        System.out.println("\t 3.删除商品\n");
        System.out.println("\t 4.查询商品\n");
        System.out.println("\t 5.显示所有商品\n");
        System.out.println("***************************");

        System.out.println("\n请输入选项,或者按 0 返回上一级菜单.");
        do
        {
            String choice = ScannerInfoString();
            String regex = "[0-5]";
            if (choice.matches(regex))
            {
                int info = Integer.parseInt(choice);
                switch (info)
                {
                    case 0:
                       mainPage();
                        break;
                    case 1:
                       GoodsPage.addGoodsPage();
                       break;
                    case 2:
                        GoodsPage.updateGoodsPage();
                        break;
                    case 3:
                        GoodsPage.deleteGoodsPage();
                        break;
                    case 4:

                        GoodsPage.queryGoosPage();

                        break;
                    case 5:

                        GoodsPage.showAllGoodsPage();

                        break;
                    default:
                        break;
                }
            }else{
                System.err.println("!输入有误!");
                System.out.println("重新输入或按 0 返回上一级菜单.");
            }

        }while(true);
    }


    /*前台收银*/
    public static  void  goCashDeskPage(){

        System.out.println("\n*******欢迎使用商超购物管理系统*******\n");
        System.out.println("\t 1.登录系统\n");
        System.out.println("\t 2.退出\n");
        System.out.println("-----------------------------");
        System.out.println("请输入选项,或者按 0 返回上一级菜单.");

        do {

            String choice = ScannerChoice.ScannerInfoString();
            String regex = "[0-2]";

            if (choice.matches(regex)){

                int info = Integer.parseInt(choice);
                switch (info){

                    case 0:
                        mainPage();
                        break;
                    case 1:
                        int loginTimes = 3;
                        while (loginTimes != 0 ){

                            loginTimes--;

                            System.out.println("----用户名-------");
                            String name = ScannerChoice.ScannerInfoString();
                            System.out.println("----密  码-------");
                            String password = ScannerChoice.ScannerInfoString();


                            ArrayList<SalesMan> list = new SalesManDao().checkStandLog(name);


                            if (list == null || list.size() <= 0 ){

                                System.err.println("\t!!用户名输入有误!!\n");
                                System.out.println("\n剩余登陆次数："+loginTimes);


                            }else{

                                SalesMan man = list.get(0);

                                if (man.getsPassWord().equals(password)){

                                    System.out.println("账户登录成功");


                                }else{
                                    System.err.println("\t!!密码错误!!\n");
                                    System.out.println("\n剩余登陆次数："+loginTimes);
                                }



                            }













                        }
                        System.out.println("密码输错3次了,您已经退出了系统");
                        System.exit(0);
                        break;
                    case 2:
                        System.out.println("您已经退出了系统");
                        System.exit(0);

                        break;
                       default:
                           break;





                }





            }else{


                System.out.println("输入错误");


            }








        }while (true);










    }

    /*商品管理*/
    public static  void  goCommodityManagementPage(){

        System.out.println("商品管理");
    }




}
